package com.grep.extra.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.grep.base.db.DBUtils;
import com.grep.base.util.MD5Encrypt;

/**
 * 
 * @author yuyang 对用户的操作
 */

public class User {

	public boolean checkUserExist(String username, String password) {
		
		String md5password = MD5Encrypt.MD5Encode(password);
		
		
		String resultString = "";
		boolean isExist = false;

		String checkSql = "select password from user where username='"+username+"'";

		Connection conn = null;
		Statement stat = null;
		ResultSet result = null;

		try {
			conn = DBUtils.getConnection();
			stat = conn.createStatement();
			result = stat.executeQuery(checkSql);
			if (result.next()) {
				resultString = result.getString(1);
			}
			if(resultString.endsWith(md5password)){
				isExist = true;
			}else{
				isExist = false;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtils.close(result);
			DBUtils.close(stat);
			DBUtils.close(conn);
		}

		return isExist;
	}

}
